<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>角色维护界面</title>
<link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
</head>
<body>
	<form class="layui-form" action="" lay-filter="example">
		<input type="hidden" id="roleId" name="roleId">
		<input type="hidden" name="rolePeople" id="rolePeople"
					placeholder="请输入创建人" class="layui-input">
		<div class="layui-form-item">
			<label class="layui-form-label">角色名称：</label>
			<div class="layui-input-block">
				<input type="text" name="roleName" id="roleName"
					placeholder="请输入用户名" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">备注：</label>
			<div class="layui-input-block">
				<input type="text" name="roleNote" id="roleNote" placeholder="请输入备注"
					class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">负责模块：</label>
			<div class="layui-form-label">
				<div id="test7" class="demo-tree"></div>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="submit" class="layui-btn" lay-submit=""
					lay-filter="demo1">立即提交</button>
			</div>
		</div>

	</form>

	<script src="../res/layui/layui.js" charset="utf-8"></script>
	<script src="../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
	<script src="../res/js/tools.js" charset="utf-8"></script>
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
	<script>
layui.use(['tree','form', 'layedit', 'laydate','upload','util'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate
  ,upload = layui.upload
  ,tree = layui.tree
  ,util = layui.util
  
  
  
  //创建一个编辑器
  var editIndex = layedit.build('LAY_demo_editor');
  //自定义验证规则
  form.verify({
    title: function(value){
      if(value.length < 2){
        return '标题至少得2个字符啊';
      }
    }
    ,pass: [
      /^[\S]{6,12}$/
      ,'密码必须6到12位，且不能出现空格'
    ]
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });
  //监听提交
  form.on('submit(demo1)', function(data){
    var url = "../../Role/RoleInsert";
    var id = "";
	  $("input[same='layuiTreeCheck']:checked").each(function(){
			id+=$(this).val()+",";
	 });
	  data.field.moduleId = id ;
    $.post(url,data.field,function(obj){
    	if(obj.state==1){
    		layer.msg(obj.msg,{
				icon:1,
			 	time:1000,
			 },function(){
				 var indexs = parent.layer.getFrameIndex(window.name);
				 parent.layer.close(indexs);
			 });
    		return false ;
    	}
    },"json")
    return false;
  });
  var id = getQueryString("id");
  var userId = getQueryString('userId');
  if(userId!=null){
	  
	 $("#rolePeople").val(userId);
  }
  if(id!=null){
	//开启复选框
	  var url = '../../Role/findByAllThree';
	  var data = {id:id}
	  $.post(url,data,function(obj){
		  tree.render({
			    elem: '#test7'
			    ,data: obj
			    ,showCheckbox: true
			  });
	  },'json')
	  var url = "../../Role/RoleById";
		var data = {id:id};
		$.post(url,data,function(obj){
			$("#roleId").val(obj.roleId);
			$("#roleName").val(obj.roleName);
			$("#roleNote").val(obj.roleNote);
		},'json')
  }else{
	//开启复选框
	  var url = '../../Role/findByAllTwo';
	  $.post(url,null,function(obj){
		  tree.render({
			    elem: '#test7'
			    ,data: obj
			    ,showCheckbox: true
			  });
	  },'json')
  }
});
</script>
</body>
</html>